//
//  String+Extension.swift
//  WBDemo
//
//  Created by Jin on 26/04/2018.
//  Copyright © 2018 com.baidu.123. All rights reserved.
//

import UIKit

extension String{
    ///快速返回一个文档目录路径
    func docDir() -> String {
        let path =  NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory,FileManager.SearchPathDomainMask.userDomainMask, true).last!
        let docPath = (path as NSString).strings(byAppendingPaths: [(self as NSString).pathComponents.last!]).last!
        return docPath
    }
    ///快速返回一个缓存路径
    func cacheDir() -> String {
        let path =  NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory,FileManager.SearchPathDomainMask.userDomainMask, true).last!
        let cachePath = (path as NSString).strings(byAppendingPaths: [(self as NSString).pathComponents.last!]).last!
        return cachePath
    }
    ///快速返回一个临时目录路径
    func tmpDir() -> String {
        let tmpPath = NSTemporaryDirectory()
        return (tmpPath as NSString).strings(byAppendingPaths: [(self as NSString).pathComponents.last!]).last!
    }
}
